﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.BaseInformation;


namespace TyMES.ViewModel.baseinformation.BatchCompilationsVMs
{
    public partial class BatchCompilationsListVM : BasePagedListVM<BatchCompilations_View, BatchCompilationsSearcher>
    {

        protected override IEnumerable<IGridColumn<BatchCompilations_View>> InitGridHeader()
        {
            return new List<GridColumn<BatchCompilations_View>>{
                this.MakeGridHeader(x => x.factoryCode),
                this.MakeGridHeader(x => x.lineCode),
                this.MakeGridHeader(x => x.stationCode),
                this.MakeGridHeader(x => x.orderCode),
                this.MakeGridHeader(x => x.scheduleCode),
                this.MakeGridHeader(x => x.materialCode),
                this.MakeGridHeader(x => x.materialName),
                this.MakeGridHeader(x => x.batchCode),
                this.MakeGridHeader(x => x.batchSingleCostQty),
                this.MakeGridHeader(x => x.batchAddQty),
                this.MakeGridHeader(x => x.batchMarginQty),
                this.MakeGridHeader(x => x.isUse),
                this.MakeGridHeader(x => x.Filed1),
                this.MakeGridHeader(x => x.Filed2),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<BatchCompilations_View> GetSearchQuery()
        {
            var query = DC.Set<BatchCompilations>()
                .CheckContain(Searcher.factoryCode, x=>x.factoryCode)
                .CheckContain(Searcher.lineCode, x=>x.lineCode)
                .CheckContain(Searcher.stationCode, x=>x.stationCode)
                .CheckContain(Searcher.orderCode, x=>x.orderCode)
                .CheckContain(Searcher.scheduleCode, x=>x.scheduleCode)
                .CheckContain(Searcher.materialCode, x=>x.materialCode)
                .CheckContain(Searcher.materialName, x=>x.materialName)
                .CheckContain(Searcher.batchCode, x=>x.batchCode)
                .CheckContain(Searcher.batchSingleCostQty, x=>x.batchSingleCostQty)
                .CheckEqual(Searcher.isUse, x=>x.isUse)
                .CheckContain(Searcher.Filed1, x=>x.Filed1)
                .CheckContain(Searcher.Filed2, x=>x.Filed2)
                .Select(x => new BatchCompilations_View
                {
				    ID = x.ID,
                    factoryCode = x.factoryCode,
                    lineCode = x.lineCode,
                    stationCode = x.stationCode,
                    orderCode = x.orderCode,
                    scheduleCode = x.scheduleCode,
                    materialCode = x.materialCode,
                    materialName = x.materialName,
                    batchCode = x.batchCode,
                    batchSingleCostQty = x.batchSingleCostQty,
                    batchAddQty = x.batchAddQty,
                    batchMarginQty = x.batchMarginQty,
                    isUse = x.isUse,
                    Filed1 = x.Filed1,
                    Filed2 = x.Filed2,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class BatchCompilations_View : BatchCompilations{

    }
}
